package com.labofjet.blogv3.facade;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.stereotype.Component;

import com.labofjet.blogv3.model.Artical;
import com.labofjet.blogv3.model.Category;
import com.labofjet.blogv3.model.History;
import com.labofjet.blogv3.model.User;
import com.labofjet.blogv3.service.impl.ArticalService;
import com.labofjet.blogv3.service.impl.CategoryService;
import com.labofjet.blogv3.service.impl.HistoryService;
import com.labofjet.blogv3.service.impl.UserService;

@Component
public class ManageFacade {
	@Autowired
	private UserService userService;

	@Autowired
	private HistoryService historyService;

	@Autowired
	private CategoryService categoryService;

	@Autowired
	private ArticalService articalService;

	public User findUser(String userName, String password) {
		return userService.findOne(userName, password);
	}
	
	public User findUser(long id) {
		return userService.findOne(id);
	}

	public void save(Artical artical) {
		articalService.save(artical);
	}

	public void save(History history) {
		historyService.save(history);
	}

	public void save(Category c) {
		categoryService.save(c);
	}

	public List<Category> findAllCategories() {
		return categoryService.findAll();
	}

	public void deleteCategory(long id) {
		categoryService.delete(id);
	}

	public Artical findArtical(long id) {
		return articalService.findArtical(id);
	}

	public void updateArtical(Artical artical) {
		Artical old = articalService.findArtical(artical.getId());
		old.setHtmlContent(artical.getHtmlContent());
		old.setIntroduction(artical.getIntroduction());
		old.setLevel(artical.getLevel());
		old.setRawContent(artical.getRawContent());
		old.setTitle(artical.getTitle());
		old.setCategories(artical.getCategories());
		articalService.save(old);
	}

	public void deleteArtical(long id) {
		Artical old = articalService.findArtical(id);
		old.setDelete(true);
		articalService.save(old);
	}

}
